﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace LogikBug.ModularMvc.Navigation
{
	public class MenuItemCollection : Collection<MenuItem>
	{
		#region Constructors

		public MenuItemCollection()
		{
		}

		public MenuItemCollection(IEnumerable<MenuItem> collection) : base(collection.ToList())
		{
		}

		#endregion

		#region Methods

		public void AddRange(IEnumerable<MenuItem> menuItems)
		{
			foreach (var menuItem in menuItems)
			{
				Add(menuItem);
			}
		}

		public override string ToString()
		{
			return ToMvcHtmlString().ToHtmlString();
		}

		public MvcHtmlString ToMvcHtmlString()
		{
			return ToMvcHtmlString(MenuNode.Li);
		}

		public MvcHtmlString ToMvcHtmlString(MenuNode menuNode)
		{
			var sb = new StringBuilder();

			foreach (var menuItem in Items)
			{
				sb.Append(menuItem.ToMvcHtmlString(MenuNode.Create(menuNode)));
			}

			return MvcHtmlString.Create(sb.ToString());
		}

		#endregion
	}
}
